const { Client } = require('@elastic/elasticsearch')

const client = new Client({
  node: 'http://localhost:9200',
  maxRetries: 5,
  requestTimeout: 60000,
  sniffOnStart: true
})

//client.info(console.log)

async function run() {
    await client.index({
      index: 'gallery',
      body: {
        title: 'jk beaurytua',
        text: 'jk 小雪姐姐就太漂亮了',
        docid: 'NEi4e9MJ3S6F'
      }
    })
    await client.index({
      index: 'gallery',
      index: 'gallery',
      body: {
        title: 'abcdfajfs',
        text: '贝尔法斯特  女仆装最棒了我爱死了',
        docid: 'YOrZw1rrT6Kb'
      }
    })
  // Let's start by indexing some data
  /*

  
    
   
    await client.index({
      index: 'test',
      // type: '_doc', // uncomment this line if you are using Elasticsearch ≤ 6
      body: {
        title: 'this is a public',
        text: '群友的正常男装'
      }
    })
  
     await client.index({
      index: 'test',
      // type: '_doc', // uncomment this line if you are using Elasticsearch ≤ 6
      body: {
        title: 'this is a test path',
        text: '群友喜欢的Loli'
      }
    })
  */
  // here we are forcing an index refresh, otherwise we will not
  // get any result in the consequent search
  await client.indices.refresh({ index: 'test' })

  // Let's search!
  const { body } = await client.search({
    index: 'test',
    // type: '_doc', // uncomment this line if you are using Elasticsearch ≤ 6
    body: {
      query: {
        "multi_match": {
          "query": "女装",
          "type": "most_fields",
          "fields": ["title", "text"]
        }
      }
    }
  })

  console.log(body.hits.hits)
}

run()
